package com.www.applyword.ui.chat;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.base.BaseFragment;
import com.www.applyword.bean.ChoiceDedilBean;
import com.www.applyword.bean.ParamsBean;
import com.www.applyword.fragment.ChoiceNewFragment;
import com.www.applyword.fragment.ChoiceNewFragment10;
import com.www.applyword.fragment.ChoiceNewFragment2;
import com.www.applyword.fragment.ChoiceNewFragment3;
import com.www.applyword.fragment.ChoiceNewFragment4;
import com.www.applyword.fragment.ChoiceNewFragment5;
import com.www.applyword.fragment.ChoiceNewFragment6;
import com.www.applyword.fragment.ChoiceNewFragment7;
import com.www.applyword.fragment.ChoiceNewFragment8;
import com.www.applyword.fragment.ChoiceNewFragment9;
import com.www.applyword.fragment.OrderSettlementFragment;
import com.www.applyword.fragment.OrderSettlementFragment2;
import com.www.applyword.fragment.OrderSettlementFragment3;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.main.LoginActivity;
import com.www.applyword.utils.ViewPagerUtil;

import net.lucode.hackware.magicindicator.MagicIndicator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2020/7/30 0030 18:25
 * version: 1.0
 * @author Administrator
 */
public class ChoiceJobActivity extends BaseActivity {
    @BindView(R.id.tablayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    @BindView(R.id.magic_indicator)
    MagicIndicator magicIndicator;

    private  ChoiceNewFragment tabFragment;

    private List<Fragment> fragments = new ArrayList<>();
    private List<String> tabs = new ArrayList<>();


    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.choice_activity);
        setTitle("线上兼职");
    }

    @Override
    protected void loadData() {
        tabs.clear();
        fragments.clear();
      /*  fragments.add(new ChoiceNewFragment());
        fragments.add(new ChoiceNewFragment2());
        fragments.add(new ChoiceNewFragment3());
        fragments.add(new ChoiceNewFragment4());
        fragments.add(new ChoiceNewFragment5());
        fragments.add(new ChoiceNewFragment6());
        fragments.add(new ChoiceNewFragment7());
        fragments.add(new ChoiceNewFragment8());
        fragments.add(new ChoiceNewFragment9());
        fragments.add(new ChoiceNewFragment10());*/
       // fragments.add(new ChoiceNewFragment11());
     //   fragments.add(new ChoiceNewFragment12());
     //   fragments.add(new ChoiceNewFragment13());
      //  fragments.add(new ChoiceNewFragment14());
       int type2 = getIntent().getIntExtra("type", 0);
        String classificationId =  getIntent().getStringExtra("classificationId");
        Map<String, Object> params = new HashMap<>();
        ParamsBean paramsBean = new ParamsBean();
        params.put("classificationId", classificationId);
        params.put("appKey", paramsBean.getAppKey());
        params.put("townId", paramsBean.getTownId());
        params.put("version", paramsBean.getVersion());
        params.put("versionCode", paramsBean.getVersionCode());
        params.put("channel", paramsBean.getChannel());
        params.put("downloadSource", paramsBean.getDownloadSource());
        params.put("deviceId", paramsBean.getDeviceId());
        params.put("osVersionName", paramsBean.getOsVersionName());
        params.put("timestamp", paramsBean.getTimestamp());
        params.put("sign", paramsBean.getSign());
        params.put("model", paramsBean.getModel());
        params.put("brand", paramsBean.getBrand());
        params.put("product", paramsBean.getProduct());
        params.put("sdkversion", paramsBean.getSdkversion());
        params.put("imei", paramsBean.getImei());
        params.put("androidid", paramsBean.getAndroidid());
        HttpClient.post(ChoiceJobActivity.this, Constants.listClassByParentId, params, new CallBack<List<ChoiceDedilBean>>() {
            @Override
            public void onSuccess(List<ChoiceDedilBean> result) {
                for (int i = 0; i < result.size(); i++) {
                        tabs.add(result.get(i).getName());
                    //创建Fragment
                  //  ChoiceNewFragment tabFragment = new ChoiceNewFragment();
                    //创建bundle对象存入需要传给Fragment的值

                    fragments.add(ChoiceNewFragment.newInstance(i,type2,result.get(i).getClassificationId()));
                }
             //   ViewPagerUtil.initViewPage3(ChoiceJobActivity.this, getSupportFragmentManager(), magicIndicator, viewPager, fragments, tabs, 1);
                //设置TabLayout的模式
                viewPager.setAdapter(new TabAdapter(getSupportFragmentManager()));
                //关联ViewPager和TabLayout
                tabLayout.setupWithViewPager(viewPager);
                viewPager.setCurrentItem(type2);
                //viewpaer一次加载全部页面
                viewPager.setOffscreenPageLimit(fragments.size());
            }
        });
    }


    class TabAdapter extends FragmentPagerAdapter {
        public TabAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        //显示标签上的文字
        @Override
        public CharSequence getPageTitle(int position) {
            return tabs.get(position);
        }
    }
}
